package cn.sc.summer.exception.enums;

import cn.sc.summer.exception.asserts.AssertExceptionAssert;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 异常类型枚举类
 *
 * @author a-xin
 * @date 2023/1/19 2:14 PM
 */
@Getter
@AllArgsConstructor
public enum AssertExceptionEnum implements AssertExceptionAssert {

    NORMAL_ASSERT_EXCEPTION(502, "Assertion anomalies!");

    private final String message;
    private final Integer code;

    AssertExceptionEnum(int code, String message) {
        this.message = message;
        this.code = code;
    }

    public static String getMessage(Integer code) {
        for (AssertExceptionEnum c : AssertExceptionEnum.values()) {
            if (Objects.equals(c.getCode(), code)) {
                return c.message;
            }
        }
        return null;
    }

    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }

}
